package com.cory.boot.support.mybatis;

import java.util.List;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import com.cory.boot.support.mybatis.interceptor.AllPageTotalHelper;
import com.cory.boot.support.mybatis.interceptor.CustomParamInterceptor;

/**
 * @author xiongcong
 * @date 2022-04-27
 */
@Configuration
public class MybatisInterceptorAutoConfiguration implements ApplicationListener<ContextRefreshedEvent> {
    
    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(new AllPageTotalHelper());
            sqlSessionFactory.getConfiguration().addInterceptor(new CustomParamInterceptor());
        }
    }
}
